import javax.media.opengl.GL2;


public class Box {
	Point o;
	double[] dim;
	
	public Box(Point origin, double x, double y, double z)
	{
		o = origin;
		double[] dim = {x, y, z};
		this.dim = dim;
	}
	
	public void render(GL2 gl)
	{
		
		// WALLS
		float[] c = {0f, 0f, 0f, 0f};
		gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE,c, 1);
		gl.glBegin(GL2.GL_QUADS);
		gl.glVertex3d(o.x		, o.y		, o.z		);
		gl.glVertex3d(o.x		, o.y+dim[1], o.z		);
		gl.glVertex3d(o.x+dim[0], o.y+dim[1], o.z		);
		gl.glVertex3d(o.x+dim[0], o.y		, o.z		);
		gl.glEnd();
		
		gl.glBegin(GL2.GL_QUADS);
		gl.glVertex3d(o.x+dim[0], o.y+dim[1], o.z		);
		gl.glVertex3d(o.x+dim[0], o.y		, o.z		);
		gl.glVertex3d(o.x+dim[0], o.y		, o.z+dim[2]);
		gl.glVertex3d(o.x+dim[0], o.y+dim[1], o.z+dim[2]);
		gl.glEnd();
		
		gl.glBegin(GL2.GL_QUADS);
		gl.glVertex3d(o.x+dim[0], o.y		, o.z+dim[2]);
		gl.glVertex3d(o.x+dim[0], o.y+dim[1], o.z+dim[2]);
		gl.glVertex3d(o.x		, o.y+dim[1], o.z+dim[2]);
		gl.glVertex3d(o.x		, o.y		, o.z+dim[2]);
		gl.glEnd();
		
		gl.glBegin(GL2.GL_QUADS);
		gl.glVertex3d(o.x		, o.y+dim[1], o.z+dim[2]);
		gl.glVertex3d(o.x		, o.y		, o.z+dim[2]);
		gl.glVertex3d(o.x		, o.y		, o.z		);
		gl.glVertex3d(o.x		, o.y+dim[1], o.z		);
		gl.glEnd();
		
		//TOP
		gl.glBegin(GL2.GL_QUADS);
		gl.glVertex3d(o.x+dim[0], o.y+dim[1], o.z+dim[2]);
		gl.glVertex3d(o.x		, o.y+dim[1], o.z+dim[2]);
		gl.glVertex3d(o.x		, o.y+dim[1], o.z);
		gl.glVertex3d(o.x+dim[0], o.y+dim[1], o.z);
		gl.glEnd();
		
		//BOTTOM
		gl.glBegin(GL2.GL_QUADS);
		gl.glVertex3d(o.x+dim[0], o.y		, o.z+dim[2]);
		gl.glVertex3d(o.x		, o.y		, o.z+dim[2]);
		gl.glVertex3d(o.x		, o.y		, o.z);
		gl.glVertex3d(o.x+dim[0], o.y		, o.z);
		gl.glEnd();
		
		gl.glLineWidth(2);
		float[] d = {1f, 1f, 1f, 1f};
		gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE,d, 1);
		
		gl.glBegin(GL2.GL_LINE_LOOP);
		gl.glVertex3d(o.x		, o.y		, o.z		);
		gl.glVertex3d(o.x		, o.y+dim[1], o.z		);
		gl.glVertex3d(o.x+dim[0], o.y+dim[1], o.z		);
		gl.glVertex3d(o.x+dim[0], o.y		, o.z		);
		gl.glEnd();
		
		gl.glBegin(GL2.GL_LINE_LOOP);
		gl.glVertex3d(o.x+dim[0], o.y+dim[1], o.z		);
		gl.glVertex3d(o.x+dim[0], o.y		, o.z		);
		gl.glVertex3d(o.x+dim[0], o.y		, o.z+dim[2]);
		gl.glVertex3d(o.x+dim[0], o.y+dim[1], o.z+dim[2]);
		gl.glEnd();
		
		gl.glBegin(GL2.GL_LINE_LOOP);
		gl.glVertex3d(o.x+dim[0], o.y		, o.z+dim[2]);
		gl.glVertex3d(o.x+dim[0], o.y+dim[1], o.z+dim[2]);
		gl.glVertex3d(o.x		, o.y+dim[1], o.z+dim[2]);
		gl.glVertex3d(o.x		, o.y		, o.z+dim[2]);
		gl.glEnd();
		
		gl.glBegin(GL2.GL_LINE_LOOP);
		gl.glVertex3d(o.x		, o.y+dim[1], o.z+dim[2]);
		gl.glVertex3d(o.x		, o.y		, o.z+dim[2]);
		gl.glVertex3d(o.x		, o.y		, o.z		);
		gl.glVertex3d(o.x		, o.y+dim[1], o.z		);
		gl.glEnd();
		
	}
	
	public static boolean intersect2D(Box a, Box b)
	{
		if(a.o.x + a.dim[0] < b.o.x || a.o.y + a.dim[1] < b.o.y)
			return false;
		if(a.o.x > b.o.x + b.dim[0] || a.o.y > b.o.y + a.dim[1] )
			return false;
		return true;
	}
}
